package com.beiding.workordersystem.common.utils;

import com.beiding.workordersystem.system.model.MyCredentials;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class MySecurityUtils {

    public static MyCredentials currentCredentials() {
        SecurityContext context = SecurityContextHolder.getContext();
        if (context == null) {
            throw new RuntimeException("未登录无法获取上下文");
        }
        Authentication authentication = context.getAuthentication();

        if (authentication == null) {
            throw new RuntimeException("未登录无法获取上下文");
        }

        return (MyCredentials) authentication.getCredentials();

    }

}
